package com.sc.everyonerentboot.controller;

import com.github.pagehelper.PageInfo;
import com.sc.everyonerentboot.pojo.Orders;
import com.sc.everyonerentboot.pojo.Result;
import com.sc.everyonerentboot.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    OrderService os;
    @RequestMapping("/add")
    public Result add(@RequestBody Orders o){
        int i=os.add(o);
        if(i>0){
            return new Result(1,"新增成功");
        }
        return new Result(0,"新增失败");
    }
    @RequestMapping("/del")
    public Result del(Integer id){
        int i=os.del(id);
        if(i>0){
            return new Result(1,"删除成功");
        }
        return new Result(0,"删除失败");
    }
    @RequestMapping("/update")
    public Result update(@RequestBody Orders o){
        System.out.println(o);
        int i=os.update(o);
        if(i>0){
            return new Result(1,"修改成功");
        }
        return new Result(0,"修改失败");
    }
    @RequestMapping("/selById")
    public Result selById(Integer id){
        Orders o=os.selById(id);
        if(o!=null){
            return new Result(1,"查询成功",o);
        }
        return new Result(0,"查询失败");
    }
    @RequestMapping("/selAll")
    public Result selAll(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "5") Integer pageSize,
            @RequestBody Orders o
    ){
        System.out.println(o);
        PageInfo<Orders> p=os.selAll(pageNum,pageSize,o);
        if(p!=null){
            return new Result(1,"新增成功",p);
        }
        return new Result(0,"新增失败");
    }
    @RequestMapping("/delAll")
    public Result delAll(@RequestBody Integer[] ids){
        int i=os.delAll(ids);
        if(i>0) return new Result(1,"删除成功");
        return new Result(0,"删除失败");
    }
}
